<!DOCTYPE html>
<html>
  
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Travian辅助</title>
    <meta name="keywords" content="淮阳网站建设|周口网站建设">
    <meta name="description" content="淮阳网站建设|周口网站建设">
    <meta content="telephone=no" name="format-detection">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <!--双引擎浏览器默认webkit打开-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
    <meta name="full-screen" content="yes">
    <link rel="stylesheet" href="__RES__/css/xcConfirm.css">
    <link rel="stylesheet" href="__RES__/css/uikit1.css">
    <script type="text/javascript" src="__RES__/js/jquery.js"></script>
    <script type="text/javascript" src="__RES__/js/xcConfirm.js"></script>
    <script type="text/javascript" src="__RES__/js/uikit.js"></script>
    <style>body{ padding:10px;} .active{color:#e4392a; border-bottom:3px solid #e4392a;} #my-id{ min-height:750px; line-height:1.8em;} #msg1,#msg2{ width:50%; font-size:12px;} #my-id li{word-wrap:break-word; word-break:normal; } .task{ width:650px; height:40px;} #bing1 .popBox{ width: 620px; height: 500px; margin-left: -285px; margin-top: -250px; } #bing1 .popBox .txtBox{ height:200px;} #bing1 .text{ width:50px;} #bing1 .text1{ width:30px;} .bing_input{ width:40px;} .bing_input_big{ width:200px; font-size:14px!important; letter-spacing:1px;} .bing_input_s{ width:20px;} .bing_input_m{ width:60px;} .link{ color:#0066CC;cursor:hand;} .link:hover{ text-decoration:underline;} .uk-nav li{ font-size:12px;} .uk-nav>li>a{ padding:1px 15px;} .resimg{ width:40px;} .b_good{ font-weight:bold; font-size:14px; color: #009900; margin:0 1em;} .b_maxLevel{ font-weight:bold; font-size:14px; color: #999999; margin:0 1em;}</style></head>
  
  <body>
    <script>$('#bing1').hide();</script>
    <input id="userinfo" type="hidden" data-uid='{$me.id}' data-name='{$me.user}' data-server='{$me.server}' data-version="{$me.version}" data-tribe="{$me.tribe}">账户： {volist name="user" id="v"}
    <span id="user{$v.id}" data-user="{$v.user}" data-pwd="{$v.pwd}">
      <a href="{:url('travian/index/index')}/uid/{$v.id}" title="{$v.server}">{if condition="$v['id'] eq input('uid')"}
        <strong>{$v.user}</strong>{else /}{$v.user}{/if}</a></span>{/volist}
    <a target="_blank" href="{:url('user_list')}">账户管理</a>
    <input name="settimeout" type="text" class="uk-margin-small-top" value="30" placeholder="循环检测时间（秒）">
    <label>
      <input type="checkbox" id="switch" checked>开启辅助</label>
    <span class="link linka" data-link="{$dorf}1.php">村外</span>　
    <span class="link linka" data-link="{$dorf}2.php">村内</span>　
    <span class="link linka" data-link="build.php?gid=19">兵营</span>　
    <span class="link linka" data-link="build.php?gid=20">马厩</span>
    <span id="msg11"></span>
    <div class="uk-grid">
      <div class="uk-width-1-1">村庄：
        <span class="link" onClick="updatev({$uid})">更新村庄</span></a>
        <div class="uk-grid">
          <div id="task_grid">
            <ul class="uk-subnav uk-subnav-pill" data-uk-switcher="{connect:'#my-id'}" id="tab1">{volist name="list" id="v"}
              <li>
                <a href="#" title="{$v.vid}">{$v.vname}</a></li>{/volist}</ul>
            <!-- 这是内容项目的容器 -->
            <ul id="my-id" class="uk-switcher">{volist name="list" id="v"}
              <table id="v{$v.vid}" width="820" border="0">
                <tr>
                  <td colspan="2" valign="top" class="">
                    <li data-vid="{$v.vid}">
                      <div>
                        <a target="_blank" href="{:url('attack_list',array('vid'=>$v['vid']))}">抢劫目标</a>
                        <br>
                        <h3>造兵设置：</h3>
                        <form name="zaobing">兵营：
                          <input type="text" class="uk-form-small bing_input" name="build" value="{$v.task_b.build|default=''}">兵种：
                          <input type="text" class="uk-form-small bing_input_big" name="ts" value="{$v.task_b.ts|default=''}">
                          <input type="hidden" class="uk-form-small bing_input" name="ft" value="t1">
                          <input type="hidden" class="uk-form-small bing_input" name="start_time" value="0">间隔：
                          <input type="text" class="uk-form-small bing_input" name="times" value="{$v.task_b.times|default='0'}">状态：
                          <select name="status">
                            <option{if condition="$v['task_b']['status'] == '1'" } selected{/if} value='1'>开启</option>
                              <option{if condition="$v['task_b']['status'] == '0'" } selected{/if} value='0'>关闭</option>
						  </select>
                          <button class="uk-button uk-button-primary set_zaobing" type="button">设置</button>
						</form>
                        <h3>逃逸设置：</h3>
                        <form name="escape">X：
                          <input type="text" class="uk-form-small bing_input" name="x" value="{$v.task_4.x|default=''}">Y：
                          <input type="text" class="uk-form-small bing_input" name="y" value="{$v.task_4.y|default=''}">间隔：
                          <input type="text" class="uk-form-small bing_input" name="times" value="{$v.task_4.times}">排除：
                          <input type="text" class="uk-form-small bing_input" name="except" value="{$v.task_4.except}">状态：
                          <select name="status">
                            <option{if condition="$v['task_4']['status'] == '1'" } selected{/if} value='1'>开启</option>
                              <option{if condition="$v['task_4']['status'] == '0'" } selected{/if} value='0'>关闭</option></select>
                          <button class="uk-button uk-button-primary set_task4" type="button">设置</button></form>
                        <h3>运输设置：</h3>
                        <form name="transport">目标村：
                          <input type="text" class="uk-form-small bing_input_m" name="target_vid" value="{$v.task_5.target_vid|default=''}">木：
                          <input type="text" class="uk-form-small bing_input_m" name="mu" value="{$v.task_5.mu|default=''}">土：
                          <input type="text" class="uk-form-small bing_input_m" name="tu" value="{$v.task_5.tu|default=''}">铁：
                          <input type="text" class="uk-form-small bing_input_m" name="tie" value="{$v.task_5.tie|default=''}">粮：
                          <input type="text" class="uk-form-small bing_input_m" name="liang" value="{$v.task_5.liang|default=''}">间隔：
                          <input type="text" class="uk-form-small bing_input_s" name="times" value="{$v.task_5.times}">下次：
                          <input type="text" class="uk-form-small bing_input_s" name="start_time" value="{$v.task_5.start_time}">状态：
                          <select name="status">
                            <option{if condition="$v['task_5']['status'] == '1'" } selected{/if} value='1'>开启</option>
                              <option{if condition="$v['task_5']['status'] == '0'" } selected{/if} value='0'>关闭</option></select>
                          <button class="uk-button uk-button-primary set_task6" type="button">设置</button></form>
                        <h3>建：</h3>
                        <div id="taskbox_build" class="task">{volist name="v['task']" id="v2"}
                          <button class="uk-button uk-button-mini" type="button" data-tid="{$v2.id}" data-bid="{$v2.build}" data-title="{$v2.title}" data-title="{$v2.type}" data-onclick="addtask({$v.vid},{$v2.build})" onClick="deltask({$v2.id},{$v2.build})">{$v2.build}：{$v2.title}</button>{/volist}</div>
                        <h3>练：</h3>
                        <div id="taskbox_tiejiang">{volist name="v['task_tiejiang']" id="v4"}
                          <button class="uk-button uk-button-mini" type="button" data-tieid="{$v4.id}" data-t="{$v4.t}" data-title="{$v4.title}" data-level="{$v4.level}" onClick="deltask_tiejiang({$v4.id})">{$v4.title}={$v4.level}</button>{/volist}</div>
                        <h3>拆：</h3>
                        <div id="taskbox_des">{volist name="v['task_chai']" id="v3"}
                          <button class="uk-button uk-button-mini" type="button" data-chaiid="{$v3.id}" data-onclick="addtask_chai({$v.vid},{$v3.build})" onClick="deltask_chai({$v3.id})">{$v3.build}：{$v3.title}</button>{/volist}</div></li>
                  </td>
                </tr>
                <tr>
                  <td id="msg1">msg1</td>
                  <td id="msg2">msg2</td></tr>
                <tr>
                  <td colspan="2">
                    <span>
                      <input name="reslevel" type="text" class="uk-margin-small-top" value="10" placeholder="资源田等级"></span>
                    <span id="msg3"></span>
                  </td>
                </tr>
              </table>{/volist}</ul>
            </div>
          </div>
          <div class="uk-panel uk-panel-box">
            <button class="uk-button uk-button-primary" type="button" onClick="read_viliage(0)">读取村庄</button>
            <button class="uk-button uk-button-primary" type="button" id="start_task" onClick="startBot();dis()">开始任务</button>
            <button class="uk-button uk-button-primary" type="button" id="start_task">停止任务</button>
            <button class="uk-button uk-button-primary" type="button" id="test1">测试按钮</button></div>
        </div>
      </div>
  </body>
  <script>var uid = $('#userinfo').attr('data-uid');
    var server = $("#userinfo").attr('data-server');
    var tribe = $('#userinfo').attr('data-tribe');
    var settimeout;
    $('.linka').click(function() {
      var linka = $(this).attr('data-link');
      window.open(server + linka);
    });

    $("#task_grid").on("click", ".addtask",
    function() {
      var this1 = $(this);
      var menu = $(this).parent().parent().parent();
      var input = $(this).attr('data-input');
      var obj = {};
      var level;
      var vid = $(this).attr('data-vid');
      var bid = $(this).attr('data-buildid');
      var title = $(this).attr('data-title');
      var tt = title;
      var level = $(this).text();
      var type = $(this).attr('data-type');
      if (type == 'xinjian') {
        var newbid = $(this).attr('data-newbid');
        obj['newbid'] = newbid;
        title = 'NEW ' + title;
        level = 1;
      } else if (type == 'ptian') {
        level = $('#v' + vid + ' [name="reslevel"]').val();
        title = title + ' ↑ ' + level;
      } else {
        title = title + ' ↑ ' + level;
      }
      //alert($('[name="reslevel"]').val());return false;
      obj['vid'] = vid;
      obj['bid'] = bid;
      obj['title'] = title;
      obj['level'] = level;
      obj['type'] = type;
      $.get("{:url('add_build')}", obj,
      function(res) {
        if (res.res == 1) {
          var btn = ' <button class="uk-button uk-button-mini" type="button" data-tid="' + res.id + '" data-bid="' + bid + '" data-title="' + tt + '" data-type="' + type + '" data-onclick="addtask(' + res.id + ',' + bid + ')" onclick="deltask(' + res.id + ',' + bid + ')">' + bid + '：' + title + '</button>';
          $('li[data-vid="' + vid + '"] #taskbox_build').append(btn);
          if (input == 'menu') {
            menu.hide();
          }
          //$('#my-id').append('btn------666----------------');
          //新建则添加 可以升级的按钮
          if (type == 'xinjian') {
            html = '';
            if (level * 1 < 20) {
              html = '<div class="uk-button-dropdown" data-uk-dropdown="{mode:\'click\'}" aria-haspopup="true" aria-expanded="false"><button class="uk-button uk-button-primary uk-button-small" type="button">+</button><div class="uk-dropdown uk-dropdown-small"><ul class="uk-nav uk-nav-dropdown">';
              for (d = level * 1 + 1; d <= 20; d++) {
                html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + bid + '" data-title="' + title + '" data-type="danjian" data-input="menu">' + d + '</a></li>';
              }
              html += '</ul></div></div>';
            }
            if (title == '研发所') {
              html += '研发';
            }
            //var dorf2html='<div data-bid="'+bid+'">'+bid + ' <span>'+title+" 等级 "+level+'</span> '+html+'</div>';
            this1.parent().parent().parent().parent().parent().html(bid + ' <span>' + title + " 等级 " + level + '</span> ' + html);
          }
        } else {
          alert('添加任务失败');
        }
      });
    });

    $("#task_grid").on("click", ".addtask_tiejiang",
    function() {
      var this1 = $(this);
      var menu = $(this).parent().parent().parent();
      var input = $(this).attr('data-input');
      var obj = {};
      var level;
      var menu = $(this).parent().parent().parent();
      var level = prompt("请输入等级", "20");
      var vid = $(this).attr('data-vid');
      var t = $(this).attr('data-t');
      var title = $(this).attr('data-title');

      obj['vid'] = vid;
      obj['title'] = title;
      obj['level'] = level;
      obj['t'] = t;
      $.get("{:url('add_tiejiang')}", obj,
      function(res) {
        if (res.res == 1) {
          var btn = ' <button class="uk-button uk-button-mini" type="button" data-tieid="' + res.id + '" data-title="' + title + '" data-t="' + t + '" onclick="deltask_tiejiang(' + res.id + ')">' + title + '=' + level + '</button>';
          $('li[data-vid="' + vid + '"] #taskbox_tiejiang').append(btn);
          if (input == 'menu') {
            menu.hide();
          }
          //$('#my-id').append('btn------666----------------');
        } else {
          alert('添加练兵任务失败');
        }
      });
    });

    function dis() {
      $('#start_task').attr("disabled", true);
    }

    function timeb(timeb) {
      times = timeb.split(':'); //times倒计时数组（小时，分钟，秒）
      timesec = (times[0] * 3600 + times[1] * 60 + times[2] * 1); //timesec是倒计时 毫秒
      return timesec;
    }

    function updatev(uid) {
      var vids = {},
      arr_v = [],
      arr_vname = [];
      $.get(server + "{$dorf3}?&m=" + Math.random(),
      function(dorf1) {
        $(dorf1).find('{$node1}').each(function() {
          var href = $(this).find('{$node2}').attr('href');
          var vid = href.split('=')[1];
          var vname = $(this).find('{$node2}').text();
          arr_v.push(vid);
          arr_vname.push(vname);
        });
        var str = arr_v.join(',');
        var strname = arr_vname.join(',');
        vids['str'] = str;
        vids['strname'] = strname;
        vids['uid'] = {$uid};
        if (arr_v.length > 0) {
          $.get("{:url('update_v')}", vids,
          function(res) {
            if (res == 1) {
              location.reload();
            } else {
              alert('没有变动');
            }
          });
        }
      });
    }

    function read_viliage(vid) {
      if (vid == 0) {
        var vid = $('#tab1 .uk-active a').attr('title');
      }
      $.get(server + "{$dorf}1.php?{$newdid}=" + vid + '&m=' + Math.random(),
      function(dorf1) {
        if ($(dorf1).find(".loginTable").length > 0) {
          $("#message1").html("你还没有登陆游戏，请先登录！");
          $("#msg1").html("你还没有登陆游戏，请先登录！");
        } else {
          var html, jinum, buildid, title, href, str, arr, level, dorf1html = '';
          $(dorf1).find('map area[title!="{$VillageCenter}"]').each(function() {
            str = $(this).attr('title');
            str = str.replace('Woodcutter', "伐木场");
            str = str.replace('Clay Pit', "黏土矿");
            str = str.replace('Iron Mine', "铁矿场");
            str = str.replace('Wheat Field', "农场");
            str = str.replace('level', "等级");
            //tr44
            str = str.replace('Bosque', "伐木场");
            str = str.replace('Poço de Barro', "黏土矿");
            str = str.replace('Mina de Ferro', "铁矿场");
            str = str.replace('Campo de Cereal', "农场");
            str = str.replace('nível', "等级");

            if (str.indexOf(' Custo do melhoramento para nível') >= 0) {
              var ns1 = 0;　
              var ns2 = str.indexOf(" Custo do melhoramento para nível");　str = str.substring(ns1, ns2);
            }
            str = str.replace("<div style='color:#FFF'><b>", "");
            str = str.replace("</b>", "");
            str = str.replace("</div>", "");
            arr = str.split(' ');
            var n = arr.length;
            //找出名称
            title = arr[n - 3];
            //找出等级
            level = arr[n - 1];
            //找出bid
            href = $(this).attr('href');
            var arr_href = href.split('=');
            buildid = arr_href[1];
            html = '';
            if (level * 1 < 20) {
              html = '<div class="uk-button-dropdown" data-uk-dropdown="{mode:\'click\'}" aria-haspopup="true" aria-expanded="false"><button class="uk-button uk-button-primary uk-button-small" type="button">+</button><div class="uk-dropdown uk-dropdown-small uk-dropdown-top"><ul class="uk-nav uk-nav-dropdown">';
              for (d = level * 1 + 1; d <= 20; d++) {
                html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-title="' + title + '" data-type="danjian" data-input="menu">' + d + '</a></li>';
              }
              html += '</ul></div></div>';
            }
            dorf1html += buildid + ' ' + title + " 等级 " + level + ' ' + html + "<br/>";
          });
          $("#v" + vid + " #msg1").html(dorf1html);
          var reshtml = '<button class="uk-button uk-button-primary uk-button-small addtask" type="button" data-vid="' + vid + '" data-buildid="' + buildid + '" data-title="P资源田按库存" data-type="ptian">按资源库存升级</button>';
          $("#v" + vid + " #msg3").html(reshtml);
          //var dorfa = $(dorf1).find("#logo").html();
          //alert("fff");
        }
      });

      $.get(server + "{$dorf}2.php?{$newdid}=" + vid + '&m=' + Math.random(),
      function(dorf2) {
        if ($(dorf2).find(".loginTable").length > 0) {
          $("#message1").html("你还没有登陆游戏，请先登录！");
          $("#v" + vid + " #msg1").html("你还没有登陆游戏，请先登录！");
        } else {
          var html, jinum, buildid, title, href, str, arr, level, dorf2html = '', kk = 0, g, h;
          $(dorf2).find("area").each(function() {
            str = $(this).attr('title');
            //预先定空地
            str = str.replace('Building site', "空地");
            str = str.replace('Outer building site', "空地");
            str = str.replace('Rally Point building site', "空地");
			str = str.replace('建筑工地', "空地");
            //预先定于大仓库大粮仓
            str = str.replace('Great Warehouse', "大仓库");
            str = str.replace('Great Granary', "大粮仓");
            //
            str = str.replace('place empty', "空地");
            str = str.replace('buildin place wall', "城墙位置");
            str = str.replace('Rally Point', "集结点");
            str = str.replace('City Wall', "城墙");
            str = str.replace('Sawmill', "木材厂");
            str = str.replace('Brickworks', "砖块厂");
            str = str.replace('Iron Foundry', "铸造厂");
            str = str.replace('Flour Mill', "磨坊");
            str = str.replace('Bakery', "面包房");
            str = str.replace('Warehouse', "仓库");
            str = str.replace('Granary', "粮仓");
            //
            str = str.replace('Blacksmith', "兵工厂");
            str = str.replace('Armory', "军械库");
            str = str.replace('Tournament Square', "竞技场");
            str = str.replace('Main Building', "中心大楼");
            str = str.replace('Marketplace', "市场");
            str = str.replace('Embassy', "大使馆");
            str = str.replace('Barracks', "兵营");
            str = str.replace('Stable', "马厩");
            str = str.replace('Siege Workshop', "工场");
            str = str.replace('Academy', "研发所");
            str = str.replace('Town Hall', "市政厅");
            str = str.replace('Residence', "行宫");
            str = str.replace('Palace', "皇宫");
            str = str.replace('Treasury', "宝库");
            str = str.replace('Trade Office', "交易所");
            str = str.replace('Great Barracks', "大兵营");
            str = str.replace('Great Stable', "大马厩");
            str = str.replace('Heros Mansion', "英雄园");
            str = str.replace('Stonemason', "石匠铺");
            str = str.replace('Brewery', "酿酒厂");
            str = str.replace('Horse Drinking Pool', "饮马槽");
            str = str.replace('Stable', "马厩");
            str = str.replace('level', "等级");
            //tr44
            str = str.replace('nível', "等级");
            str = str.replace('Zona para construção', "空地");
            str = str.replace('Edifício Principal', "中心大楼");
            str = str.replace('Celeiro', "粮仓");
            str = str.replace('Armazém', "仓库");
            str = str.replace('Ponto de Reunião Militar', "集结点");
            str = str.replace('Palisade', "城墙");
            str = str.replace('Quartel', "兵营");
            str = str.replace('Academia', "研发所");
            str = str.replace('Cavalaria', "马厩");
            str = str.replace('Smithy', "兵工厂");
            str = str.replace('Mercado', "市场");
            str = str.replace('Residência', "行宫");
            str = str.replace('Grain Mill', "磨坊");
            str = str.replace('Sawmill', "木材厂");
            str = str.replace('Brickworks', "砖块厂");
            str = str.replace('Iron Foundry', "铸造厂");
            str = str.replace('Palácio', "皇宫");
            str = str.replace('Horse Drinking Pool', "饮马槽");
            str = str.replace('Tavern', "英雄园");
            str = str.replace('StoneMason', "石匠铺");
            str = str.replace('Oficina', "工场");
            str = str.replace('Tesouraria', "宝库");
            str = str.replace('City Wall', "罗马城墙");
            str = str.replace('Companhia do Comércio', "交易所");
            str = str.replace('Praça de Torneios', "竞技场");
            str = str.replace('Embaixada', "大使馆");
            str = str.replace('Town Hall', "市政厅");
            str = str.replace('World Wonder', "世界奇迹");
            //替换掉多余内容
            if (str.indexOf('Custo do melhoramento para nível') >= 0) {
              var ns1 = 0;　
              var ns2 = str.indexOf("Custo do melhoramento para nível");　str = str.substring(ns1, ns2);
            }
            str = str.replace("<div style='color:#FFF'><b>", "");
            str = str.replace("<div style=color:#FFF><b>", "");
            str = str.replace("</b>", "");
            str = str.replace("</div>", "");
            arr = str.split(' ');
            var n = arr.length;

            //找出bid
            href = $(this).attr('href');
            var arr_href = href.split('=');
            buildid = arr_href[1];

            if (str == '空地') {
              title = str;
              //如果任务里有此新建建筑
              if ($('li[data-vid="' + vid + '"] #taskbox_build').find('button[data-bid="' + buildid + '"]').length > 0) {
                title = $('li[data-vid="' + vid + '"] #taskbox_build').find('button[data-bid="' + buildid + '"]').attr('data-title');
                level = 0;
              }
            } else {
              //alert(str);
              //找出名称
              title = arr[n - 3];
              //找出等级
              level = arr[n - 1];
            }

            if (title != '空地' && title != '城墙位置') {
              html = '';
              var max_level;
              if (title == '世界奇迹') {
                max_level = 100;
              } else {
                max_level = 20;
              }
              if (level * 1 < max_level) {
                html = '<div class="uk-button-dropdown" data-uk-dropdown="{mode:\'click\'}" aria-haspopup="true" aria-expanded="false"><button class="uk-button uk-button-primary uk-button-small" type="button">+</button><div class="uk-dropdown uk-dropdown-small"><ul class="uk-nav uk-nav-dropdown">';
                for (d = level * 1 + 1; d <= max_level; d++) {
                  html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-title="' + title + '" data-type="danjian" data-input="menu">' + d + '</a></li>';
                }
                html += '</ul></div></div>';
              }
              html += ' <button class="uk-button uk-button-success uk-button-small" type="button" onclick=\"addtask_chai(\'' + vid + '\',\'' + buildid + '\',\'' + title + '\');\">拆</button>';

              if (title == '研发所') {
                html += '研发';
              }
              if (title == '兵工厂') {
                html += '<div class="uk-button-dropdown" data-uk-dropdown="{mode:\'click\'}" aria-haspopup="true" aria-expanded="false"><button class="uk-button uk-button-primary uk-button-small" type="button">练兵</button><div class="uk-dropdown uk-dropdown-small"><ul class="uk-nav uk-nav-dropdown">';
                html += '<li><a class="addtask_tiejiang" data-vid="' + vid + '" data-t="1" data-title="古罗/棒子/方阵" data-input="menu">古罗/棒子/方阵</a></li>';
                html += '<li><a class="addtask_tiejiang" data-vid="' + vid + '" data-t="2" data-title="禁卫/矛兵/剑士" data-input="menu">禁卫/矛兵/剑士</a></li>';
                html += '<li><a class="addtask_tiejiang" data-vid="' + vid + '" data-t="3" data-title="帝国/斧头/侦查" data-input="menu">帝国/斧头/侦查</a></li>';
                html += '<li><a class="addtask_tiejiang" data-vid="' + vid + '" data-t="4" data-title="使节/侦查/雷法" data-input="menu">使节/侦查/雷法</a></li>';
                html += '<li><a class="addtask_tiejiang" data-vid="' + vid + '" data-t="5" data-title="帝骑/圣骑/德鲁" data-input="menu">帝骑/圣骑/德鲁</a></li>';
                html += '<li><a class="addtask_tiejiang" data-vid="' + vid + '" data-t="6" data-title="将军/日骑/海顿" data-input="menu">将军/日骑/海顿</a></li>';
                html += '<li><a class="addtask_tiejiang" data-vid="' + vid + '" data-t="7" data-title="冲车" data-input="menu">冲车</a></li>';
                html += '<li><a class="addtask_tiejiang" data-vid="' + vid + '" data-t="8" data-title="投石" data-input="menu">投石</a></li>';
                html += '</ul></div></div>';
              }
			    g = $(dorf2).find("img.building:eq("+kk+")").attr('class');
			  if(typeof(g) != "undefined"){
			    var g_arr = g.split('  ');
			    g = g_arr[g_arr.length-1];
			    //console.log(g);
			  }else{
			    g = 'no';
			  }
			  /*h = $(dorf2).find(".colorLayer[class*=\'aid"+g+"\']").attr('class');
			  console.log(h);
			  if(typeof(h) != "undefined"){
			    var h_arr = h.split(' ');
				if(h_arr[0].indexOf('colorLayer')>0){
			      h = h_arr[h_arr.length-2];
				}else{
				  h = h_arr[h_arr.length-2];
				}
			    //console.log(g);
			  }else{
			    h = 'no';
			  }*/
              dorf2html += '<div data-bid="' + buildid + '">' + buildid + ' <img class="resimg" src="__RES__/res/'+g+'-ltr.png" alt="'+title+'" title="'+title+'"><span class="b_'+h+'">'+ level +'</span> ' + html + '</div>';
              //如果是空地
            } else {
              html = '<div class="uk-button-dropdown" data-uk-dropdown="{mode:\'click\'}" aria-haspopup="true" aria-expanded="false"><button class="uk-button uk-button-primary uk-button-small" type="button">建</button><div class="uk-dropdown uk-dropdown-small"><ul class="uk-nav uk-nav-dropdown">';
              //for(d=level*1+1;d<=20;d++){
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="5" data-title="木材厂" data-type="xinjian" data-input="menu">(5)  木材厂</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="6" data-title="砖块厂" data-type="xinjian" data-input="menu">(6)  砖块厂</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="7" data-title="铸造厂" data-type="xinjian" data-input="menu">(7)  铸造厂</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="8" data-title="磨坊" data-type="xinjian" data-input="menu">(8)  磨坊</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="9" data-title="面包房" data-type="xinjian" data-input="menu">(9)  面包房</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="10" data-title="仓库" data-type="xinjian" data-input="menu">(10) 仓库</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="11" data-title="粮仓" data-type="xinjian" data-input="menu">(11) 粮仓</a></li>';
              if ($('#userinfo').attr('data-version') == '36') {
                html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="13" data-title="军械库" data-type="xinjian" data-input="menu">(13) 军械库</a></li>';
              }
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="12" data-title="兵工厂" data-type="xinjian" data-input="menu">(12) 兵工厂</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="14" data-title="竞技场" data-type="xinjian" data-input="menu">(14) 竞技场</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="15" data-title="中心大楼" data-type="xinjian" data-input="menu">(15) 中心大楼</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="16" data-title="集结点" data-type="xinjian" data-input="menu">(16) 集结点</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="17" data-title="市场" data-type="xinjian" data-input="menu">(17) 市场</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="18" data-title="大使馆" data-type="xinjian" data-input="menu">(18) 大使馆</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="19" data-title="兵营" data-type="xinjian" data-input="menu">(19) 兵营</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="20" data-title="马厩" data-type="xinjian" data-input="menu">(20) 马厩</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="21" data-title="工场" data-type="xinjian" data-input="menu">(21) 工场</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="22" data-title="研发所" data-type="xinjian" data-input="menu">(22) 研发所</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="23" data-title="山洞" data-type="xinjian" data-input="menu">(23) 山洞</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="24" data-title="市政厅" data-type="xinjian" data-input="menu">(24) 市政厅</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="25" data-title="行宫" data-type="xinjian" data-input="menu">(25) 行宫</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="26" data-title="皇宫" data-type="xinjian" data-input="menu">(26) 皇宫</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="27" data-title="宝库" data-type="xinjian" data-input="menu">(27) 宝库</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="28" data-title="交易所" data-type="xinjian" data-input="menu">(28) 交易所</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="29" data-title="大兵营" data-type="xinjian" data-input="menu">(29) 大兵营</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="30" data-title="大马厩" data-type="xinjian" data-input="menu">(30) 大马厩</a></li>';
              switch (tribe) {
              case '罗马人':
                html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="31" data-title="罗马城墙" data-type="xinjian" data-input="menu">(31) 罗马城墙</a></li>';
                break;
              case '日耳曼人':
                html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="32" data-title="日耳曼城墙" data-type="xinjian" data-input="menu">(32) 日耳曼城墙</a></li>';
                break;
              case '高卢人':
                html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="33" data-title="高卢城墙" data-type="xinjian" data-input="menu">(33) 高卢城墙</a></li>';
                break;
              }
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="34" data-title="石匠铺" data-type="xinjian" data-input="menu">(34) 石匠铺</a></li>';
              if (tribe == '日耳曼人') {
                html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="35" data-title="酿酒厂" data-type="xinjian" data-input="menu">(35) 酿酒厂</a></li>';
              }
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="36" data-title="陷阱机" data-type="xinjian" data-input="menu">(36) 陷阱机</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="37" data-title="英雄园" data-type="xinjian" data-input="menu">(37) 英雄园</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="38" data-title="大仓库" data-type="xinjian" data-input="menu">(38) 大仓库</a></li>';
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="39" data-title="大粮仓" data-type="xinjian" data-input="menu">(39) 大粮仓</a></li>';
              //}
              html += '</ul></div></div>';
              dorf2html += '<div data-bid="' + buildid + '">' + buildid + ' <span>空　　地</span>　　　' + html + '</div>';
            };
			kk++;
          });
          $("#v" + vid + " #msg2").html(dorf2html);
        }
      });
    }

    function deltask(id, buildid) {
      var btn = $(this);
      $.get("{:url('del_build')}/id/" + id,
      function(res) {
        if (res.res == 1) {
          //如果是新建，还要移除所有升级任务，和还原升级到新建
          if ($('[data-tid="' + id + '"]').attr('data-type') == 'xinjian') {
            var vid = $('#tab1 .uk-active a').attr('title');
            $('li[data-vid="' + vid + '"] #taskbox_build [data-bid="' + buildid + '"]').remove();
            //然后改为空地
            var html = '';
            html = '<div class="uk-button-dropdown" data-uk-dropdown="{mode:\'click\'}" aria-haspopup="true" aria-expanded="false"><button class="uk-button uk-button-primary uk-button-small" type="button">建</button><div class="uk-dropdown uk-dropdown-small"><ul class="uk-nav uk-nav-dropdown">';
            //for(d=level*1+1;d<=20;d++){
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="5" data-title="木材厂" data-type="xinjian" data-input="menu">(5)  木材厂</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="6" data-title="砖块厂" data-type="xinjian" data-input="menu">(6)  砖块厂</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="7" data-title="铸造厂" data-type="xinjian" data-input="menu">(7)  铸造厂</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="8" data-title="磨坊" data-type="xinjian" data-input="menu">(8)  磨坊</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="9" data-title="面包房" data-type="xinjian" data-input="menu">(9)  面包房</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="10" data-title="仓库" data-type="xinjian" data-input="menu">(10) 仓库</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="11" data-title="粮仓" data-type="xinjian" data-input="menu">(11) 粮仓</a></li>';
            if ($('#userinfo').attr('data-version') == '36') {
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="13" data-title="军械库" data-type="xinjian" data-input="menu">(13) 军械库</a></li>';
            }
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="12" data-title="兵工厂" data-type="xinjian" data-input="menu">(12) 兵工厂</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="14" data-title="竞技场" data-type="xinjian" data-input="menu">(14) 竞技场</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="15" data-title="中心大楼" data-type="xinjian" data-input="menu">(15) 中心大楼</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="16" data-title="集结点" data-type="xinjian" data-input="menu">(16) 集结点</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="17" data-title="市场" data-type="xinjian" data-input="menu">(17) 市场</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="18" data-title="大使馆" data-type="xinjian" data-input="menu">(18) 大使馆</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="19" data-title="兵营" data-type="xinjian" data-input="menu">(19) 兵营</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="20" data-title="马厩" data-type="xinjian" data-input="menu">(20) 马厩</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="21" data-title="工场" data-type="xinjian" data-input="menu">(21) 工场</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="22" data-title="研发所" data-type="xinjian" data-input="menu">(22) 研发所</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="23" data-title="山洞" data-type="xinjian" data-input="menu">(23) 山洞</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="24" data-title="市政厅" data-type="xinjian" data-input="menu">(24) 市政厅</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="25" data-title="行宫" data-type="xinjian" data-input="menu">(25) 行宫</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="26" data-title="皇宫" data-type="xinjian" data-input="menu">(26) 皇宫</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="27" data-title="宝库" data-type="xinjian" data-input="menu">(27) 宝库</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="28" data-title="交易所" data-type="xinjian" data-input="menu">(28) 交易所</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="29" data-title="大兵营" data-type="xinjian" data-input="menu">(29) 大兵营</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="30" data-title="大马厩" data-type="xinjian" data-input="menu">(30) 大马厩</a></li>';
            switch (tribe) {
            case '罗马人':
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="31" data-title="罗马城墙" data-type="xinjian" data-input="menu">(31) 罗马城墙</a></li>';
              break;
            case '日耳曼人':
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="32" data-title="日耳曼城墙" data-type="xinjian" data-input="menu">(32) 日耳曼城墙</a></li>';
              break;
            case '高卢人':
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="33" data-title="高卢城墙" data-type="xinjian" data-input="menu">(33) 高卢城墙</a></li>';
              break;
            }
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="34" data-title="石匠铺" data-type="xinjian" data-input="menu">(34) 石匠铺</a></li>';
            if (tribe == '日耳曼人') {
              html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="35" data-title="酿酒厂" data-type="xinjian" data-input="menu">(35) 酿酒厂</a></li>';
            }
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="36" data-title="陷阱机" data-type="xinjian" data-input="menu">(36) 陷阱机</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="37" data-title="英雄园" data-type="xinjian" data-input="menu">(37) 英雄园</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="38" data-title="大仓库" data-type="xinjian" data-input="menu">(38) 大仓库</a></li>';
            html += '<li><a class="addtask" data-vid="' + vid + '" data-buildid="' + buildid + '" data-newbid="39" data-title="大粮仓" data-type="xinjian" data-input="menu">(39) 大粮仓</a></li>';
            //}
            html += '</ul></div></div>';
            dorf2html = '<div data-bid="' + buildid + '">' + buildid + ' <span>空地</span> ' + html + '</div>';
            $('table[id="v' + vid + '"] #msg2 div[data-bid="' + buildid + '"]').html(dorf2html);
          }
          $('[data-tid="' + id + '"]').remove();
          //$('#my-id').append('btn------666----------------');
        } else {
          alert('移除任务失败');
        }
      });
    }

    function deltask_chai(id) {
      var btn = $(this);
      $.get("{:url('del_build_chai')}/id/" + id,
      function(res) {
        if (res.res == 1) {
          //btn.hide();
          $('[data-chaiid="' + id + '"]').remove();
          //$('#my-id').append('btn------666----------------');
        } else {
          alert('移除任务失败');
        }
      });
    }

    function deltask_tiejiang(id) {
      var btn = $(this);
      $.get("{:url('del_tiejiang')}/id/" + id,
      function(res) {
        if (res.res == 1) {
          //btn.hide();
          $('[data-tieid="' + id + '"]').remove();
          //$('#my-id').append('btn------666----------------');
        } else {
          alert('移除任务失败');
        }
      });
    }

    function addtask(vid, bid, title) {
      var obj = {};
      var level;
      //alert($('[name="reslevel"]').val());return false;
      //如果是P田
      if (bid == '0') {
        level = $('#v' + vid + ' [name="reslevel"]').val();
        title = level + title;
      } else {
        level = '0';
      }
      obj['title'] = title;
      obj['level'] = level;
      $.get("{:url('add_build')}/vid/" + vid + "/bid/" + bid, obj,
      function(res) {
        if (res.res == 1) {
          var btn = ' <button class="uk-button uk-button-mini" type="button" data-tid="' + res.id + '" data-onclick="addtask(' + res.id + ',' + bid + ')" onclick="deltask(' + res.id + ',' + bid + ')">' + title + '</button>';
          $('li[data-vid="' + vid + '"] #taskbox_build').append(btn);
          //$('#my-id').append('btn------666----------------');
        } else {
          alert('添加任务失败');
        }
      });
    }

    function addtask_chai(vid, bid, title) {
      var obj = {};
      var level;
      obj['title'] = title;
      //obj['level'] = level;
      $.get("{:url('add_build_chai')}/vid/" + vid + "/bid/" + bid, obj,
      function(res) {
        if (res.res == 1) {
          var btn = ' <button class="uk-button uk-button-mini" type="button" data-chaiid="' + res.id + '" data-onclick="addtask_chai(' + res.id + ',' + bid + ')" onclick="deltask_chai(' + res.id + ')">' + bid + '：' + title + '</button>';
          $('li[data-vid="' + vid + '"] #taskbox_des').append(btn);
          //$('#my-id').append('btn------666----------------');
        } else {
          alert('添加拆建筑任务失败');
        }
      });
    }

    function addtask_tiejiang(vid, bid, title) {
      var obj = {};
      var level;
      var name = prompt("级别", "20");
      obj['title'] = title;
      obj['level'] = level;
      $.get("{:url('set_task55')}/vid/" + vid, obj,
      function(res) {
        if (res.res == 1) {
          var btn = ' <button class="uk-button uk-button-mini" type="button" data-tid="' + res.id + '" data-onclick="addtask(' + res.id + ',' + bid + ')" onclick="deltask(' + res.id + ',' + bid + ')">' + title + '</button>';
          $('li[data-vid="' + vid + '"] #taskbox_build').append(btn);
          //$('#my-id').append('btn------666----------------');
        } else {
          alert('添加铁匠任务失败');
        }
      });
    }

    //造兵任务检测
    function startBot2() {
      $.get("{:url('get_task2')}/uid/{$uid}",
      function(data) {
        if ($(data).length > 0) {
          $.each(data,
          function(i, son) {
            //alert(i);
            var arr = [];
            arr[0] = son.id;
            arr[1] = son.vid;
            arr[2] = son.ft;
            arr[3] = son.build;
            arr[4] = son.ts;
            arr[5] = son.times;
            //arr[8] = son.start_time;
            var str = arr.toString();
            setTimeout('zao2("' + str + '")', 500);
          });
        } else {
          //startBot3();
        }
        setTimeout('startBot3()', 1000);
      });
    }

    //开始造兵
    function zao2(str) {
      var arr = str.split(",");
      var id = arr[0];
      var vid = arr[1];
      var ft = arr[2];
      var build = arr[3];
      var ts = arr[4];
      var times = arr[5];
      var url = server + "build.php?{$newdid}=" + vid;
      /*
			var build2 = arr[6];
			var t2     = arr[7];
			var ts2    = arr[8];
			*/
      var obj = {};
      if (tribe == '罗马人') {
        var a1 = 't';
      } else if (tribe == '日耳曼人') {
        var a1 = 't1';
      } else if (tribe == '高卢人') {
        var a1 = 't2';
      }
      var arr = ts.split("|");
      if (arr[0] > 0) {
        obj[a1 + '1'] = arr[0];
      }
      if (arr[1] > 0) {
        obj[a1 + '2'] = arr[1];
      }
      if (arr[2] > 0) {
        obj[a1 + '3'] = arr[2];
      }
      if (arr[3] > 0) {
        obj[a1 + '4'] = arr[3];
      }
      if (arr[4] > 0) {
        obj[a1 + '5'] = arr[4];
      }
      if (arr[5] > 0) {
        obj[a1 + '6'] = arr[5];
      }
      if (arr[6] > 0) {
        obj[a1 + '7'] = arr[6];
      }
      if (arr[7] > 0) {
        obj[a1 + '8'] = arr[7];
      }
      obj['id'] = build;
      obj['ft'] = ft;
      /*obj[t] = ts;*/
      $.ajax({
        url: url,
        type: 'post',
        cache: false,
        data: obj,
        dataType: 'html',
        success: function(data1) {
		    //登录检测
			  if ($(data1).find(".loginTable").length > 0 || $(data1).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
		}
      });
      $.get("{:url('set_task2')}/id/" + id + "/times/" + times,
      function(data) {});
    }
    /*
//开始造马（如果有）
function zao2b(str){
			var arr = str.split(",");
		    var  id    = arr[0];
		    var vid    = arr[1];
			var ft     = arr[2];
			var build2 = arr[6];
			var t2     = arr[7];
			var ts2    = arr[8];
			var times  = arr[9];
			var url = server + "build.php?{$newdid}="+vid;
			var obj = {};
			obj['id'] = build2;
			obj['ft'] = ft;
			obj[t2] = ts2;
			if(ts2*1>0){
			$.ajax({
			    url: url,
			    type: 'post',
			    cache:false, 
			    data: obj,
			    dataType: 'html',
			    success: function(data1) {
			}
			});
			}
		//setTimeout('startBot3()',1000);	
}
*/

    //抢夺任务检测
    function startBot3() {
      $.ajax({
        url: "{:url('get_task3')}/uid/{$uid}",
        type: 'get',
        cache: false,
        async: false,
        //
        data: '',
        dataType: 'json',
        success: function(data) {
          //$.get("{:url('get_task3')}/uid/{$uid}",function(data){
          //如果有目标就是1
          //var status = 0;
          //var iii = 0;var status;
          //if($(data).length>0){
          $.each(data,
          function(i, son) {
            /*
		iii++;
		if(iii>=$(data).length){
		    status = 0;
		}
		*/
            //历编每个目标
            var arr = [];
            arr[0] = son.id;
            arr[1] = son.vid;
            arr[2] = son.x;
            arr[3] = son.y;
            arr[4] = son.t;
            arr[5] = son.times;
            //arr[6] = status;
            //arr[8] = son.start_time;
            var str = arr.toString();
            setTimeout('zao3("' + str + '")', 800);
          });

          //}else{
          //sleep_b();
          //}
        }
      });
      setTimeout('startBot4()', 1000);
    }

    //开始攻击
    function zao3(str) {
      var arr1 = str.split(",");
      var id = arr1[0];
      var vid = arr1[1];
      var x = arr1[2];
      var y = arr1[3];
      var t = arr1[4];
      var times = arr1[5];
      //var status = arr1[6];
      var arr = t.split("|");
      var obj = {};
      var obj2 = {};
      if (arr[0] > 0) {
        obj['t1'] = arr[0];
        obj2['t1'] = arr[0];
      }
      if (arr[1] > 0) {
        obj['t2'] = arr[1];
        obj2['t2'] = arr[1];
      }
      if (arr[2] > 0) {
        obj['t3'] = arr[2];
        obj2['t3'] = arr[2];
      }
      if (arr[3] > 0) {
        obj['t4'] = arr[3];
        obj2['t4'] = arr[3];
      }
      if (arr[4] > 0) {
        obj['t5'] = arr[4];
        obj2['t5'] = arr[4];
      }
      if (arr[5] > 0) {
        obj['t6'] = arr[5];
        obj2['t6'] = arr[5];
      }
      if (arr[6] > 0) {
        obj['t7'] = arr[6];
        obj2['t7'] = arr[6];
      }
      if (arr[7] > 0) {
        obj['t8'] = arr[7];
        obj2['t8'] = arr[7];
      }
      if (arr[8] > 0) {
        obj['t9'] = arr[8];
        obj2['t9'] = arr[8];
      }
      if (arr[9] > 0) {
        obj['t10'] = arr[9];
        obj2['t10'] = arr[9];
      }
      if (arr[10] > 0) {
        obj['t11'] = arr[10];
        obj2['t11'] = arr[10];
      }
      obj['x'] = x;
      obj['y'] = y;
      obj['c'] = 4;
      obj['s1'] = 'ok';
      $.ajax({
        url: server + "a2b.php" + "?{$newdid}=" + vid,
        type: 'post',
        cache: false,
        async: false,
        //
        data: obj,
        dataType: 'html',
        success: function(a2b) {
		//登录检测
			  if ($(a2b).find(".loginTable").length > 0 || $(a2b).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
          if ($(a2b).find('.troop_details').length > 0) {
            //成功到发兵确认页面
            obj2['id'] = '39';
            obj2['timestamp'] = $(a2b).find('[name="timestamp"]').val();
            obj2['timestamp_checksum'] = $(a2b).find('[name="timestamp_checksum"]').val();
            obj2['ckey'] = $(a2b).find('[name="ckey"]').val();
            obj2['a'] = $(a2b).find('[name="a"]').val();
            obj2['c'] = 3;
            obj2['s1'] = 'ok';
            $.ajax({
              url: server + "a2b.php" + "?{$newdid}=" + vid,
              type: 'post',
              cache: false,
              async: false,
              //
              data: obj2,
              dataType: 'html',
              success: function(a2b2) {
			  //登录检测
			  if ($(a2b2).find(".loginTable").length > 0 || $(a2b2).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
                if ($(a2b2).find('img.g16').length > 0) {
                  //发兵成功
                  $.get("{:url('set_task3')}/id/" + id + "/times/" + times,
                  function(data) {

});
                }
              }
            });
          }
        }
      });
      /*
		if(status = 0){
		    sleep_b();
		}
		*/
    }

    function startBot4() {
      $.ajax({
        url: "{:url('get_task4')}/uid/{$uid}",
        type: 'get',
        cache: false,
        async: false,
        //
        data: '',
        dataType: 'json',
        success: function(data) {
          $.each(data,
          function(i, son) {
            //历编每个任务
            var arr = [];
            arr[0] = son.id;
            arr[1] = son.vid;
            arr[2] = son.x;
            arr[3] = son.y;
            arr[4] = son.times;
            arr[5] = son.except;
            var str = arr.toString();
            setTimeout('zao_4("' + str + '")', 500);
          });
        }
      });
      setTimeout('startBot5()', 800);
    }

    function zao_4(str) {
      var arr1 = str.split(",");
      var id = arr1[0];
      var vid = arr1[1];
      var x = arr1[2];
      var y = arr1[3];
      var times = arr1[4];
      var except = arr1[5];
      var status = 0;
      var arr_except = except.split("|");
      console.log(arr_except);
      $.ajax({
        url: server + "a2b.php" + "?{$newdid}=" + vid,
        type: 'post',
        cache: false,
        async: false,
        //
        data: '',
        dataType: 'html',
        success: function(a2ba) {
		//登录检测
			  if ($(a2ba).find(".loginTable").length > 0 || $(a2ba).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
          //var i3 = 0;
          var text;
          var obj = {};
          var obj2 = {};
          var t;
          $(a2ba).find('#troops td').each(function() {
            text = $(this).find('a').text();
            t = $(this).find('input').attr('name');
            //console.log(arr_except);
            if (text.length > 0 && arr_except.indexOf(t) < 0) {
              text = text.replace("(", "");
              text = text.replace(")", "");

              /*console.log($(this).prev());
								return false;*/
              obj[t] = text;
              obj2[t] = text;
              status = 1;
            }
          });
          //var status = arr1[6];
          //var arr = t.split("|");
          if (status == 1) {
            obj['x'] = x;
            obj['y'] = y;
            obj['c'] = 2;
            obj['s1'] = 'ok';
            $.ajax({
              url: server + "a2b.php" + "?{$newdid}=" + vid,
              type: 'post',
              cache: false,
              async: false,
              //
              data: obj,
              dataType: 'html',
              success: function(a2b) {
			  //登录检测
			  if ($(a2b).find(".loginTable").length > 0 || $(a2b).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
                if ($(a2b).find('.troop_details').length > 0) {
                  //成功到发兵确认页面
                  obj2['id'] = '39';
                  obj2['timestamp'] = $(a2b).find('[name="timestamp"]').val();
                  obj2['timestamp_checksum'] = $(a2b).find('[name="timestamp_checksum"]').val();
                  obj2['ckey'] = $(a2b).find('[name="ckey"]').val();
                  obj2['a'] = $(a2b).find('[name="a"]').val();
                  obj2['c'] = 2;
                  obj2['s1'] = 'ok';
                  $.ajax({
                    url: server + "a2b.php" + "?{$newdid}=" + vid,
                    type: 'post',
                    cache: false,
                    async: false,
                    //
                    data: obj2,
                    dataType: 'html',
                    success: function(a2b2) {
					//登录检测
			  if ($(a2b2).find(".loginTable").length > 0 || $(a2b2).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
                      if ($(a2b2).find('img.g16').length > 0) {
                        //发兵成功
                        $.get("{:url('set_task4')}/id/" + id + "/times/" + times,
                        function(data) {

});
                      }
                    }
                  });
                }
              }
            });
          }

        }
      });

    }

    //铁匠铺
    function startBot5() {
      $.ajax({
        url: "{:url('get_task5')}/uid/{$uid}",
        type: 'get',
        cache: false,
        async: false,
        //
        data: '',
        dataType: 'json',
        success: function(data) {
          $.each(data,
          function(i, son) {
            //历编每个任务
            var arr = [];
            arr[0] = son.id;
            arr[1] = son.vid;
            arr[2] = son.t;
            arr[3] = son.level;
            arr[4] = son.title;
            var str = arr.toString();
            setTimeout('zao_5("' + str + '")', 500);
          });
        }
      });
      setTimeout('startBot6()', 500);
    }

    function zao_5(str) {
      var arr1 = str.split(",");
      var id = arr1[0];
      var vid = arr1[1];
      var t = arr1[2];
      var level = arr1[3];
      var title = arr1[4];
      var status = 0;
      var timeba, nono;
      $.ajax({
        url: server + "build.php" + "?{$newdid}=" + vid + "&gid=12",
        type: 'get',
        cache: false,
        async: false,
        //
        data: '',
        dataType: 'html',
        success: function(build) {
		//登录检测
			  if ($(build).find(".loginTable").length > 0 || $(build).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
          if (tribe == '罗马人') {
            var a1 = '';
          } else if (tribe == '日耳曼人') {
            var a1 = '1';
          } else if (tribe == '高卢人') {
            var a1 = '2';
          }

          //找到位置
          if ($('#userinfo').attr('data-version') == '36') {
            var yuansu = $(build).find('img.u' + a1 + t);
            //找兵种等级
            var level_now = yuansu.parent().text();
            level_now = level_now.split(' ');
            level_now = level_now[level_now.length - 1];
            level_now = level_now.substring(0, level_now.length - 2);
          } else {
            var yuansu = $(build).find('a.zoom[onclick*="Travian.Game.unitZoom(' + a1 + t + ')"]');
            //找兵种等级
            var level_now = yuansu.parent().parent().find('.information .title .level').html();
            console.log(vid+':' + a1 + t + ':' + level_now);
            level_now = level_now.split(' ');
            level_now = level_now[level_now.length - 1];
            //console.log('::'+level_now);
          }
          //console.log('节点：'+'img.u'+a1+t+'当前等级：'+level_now);return false;
          //铁匠铺有这个兵种		  
          if (yuansu.length > 0) {
            //如果满级，或者大于等于指定等级
            if (level_now * 1 >= 20 || level_now * 1 >= level) {
              nono = 'nono2';
              timeba = 1;
            } else {
              if ($('#userinfo').attr('data-version') == '36') {
                var onclick = yuansu.parent().parent().parent().find('a.research');
              } else {
                var onclick = yuansu.parent().parent().find('.information .contractLink button');
              }
              //如果当前有可以进行铁匠升级任务
              if (onclick.length > 0) {
                if ($('#userinfo').attr('data-version') == '36') {
                  links = onclick.attr('href');
                  var html = yuansu.parent().parent().find('.details').html();
                  var n11 = html.indexOf(' title="duration">');
                  var n11 = n11 + 18;　
                  var n12 = html.length;
                  var url = server + links;
                } else {
                  onclick = onclick.attr('onclick');
                  var n15 = onclick.indexOf("window.location.href = '") + 24;　
                  var n16 = onclick.indexOf("'; return false;");　links = onclick.substring(n15, n16);
                  var html = yuansu.parent().parent().find('.information .clocks').html();
                  var n11 = html.length - 8;　
                  var n12 = html.length;　
                  var url = server + links + "&{$newdid}=" + vid;
                }
                var clocks = html.substring(n11, n12);
                //console.log(clocks);return false;
                timeba = timeb(clocks) * 1;

                //console.log('url：'+url);
                $.ajax({
                  url: url,
                  type: 'get',
                  cache: false,
                  async: false,
                  //
                  data: '',
                  dataType: 'html',
                  success: function(build2) {
				  //登录检测
			  if ($(build2).find(".loginTable").length > 0 || $(build2).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
				  
				  //找到新的等级
				  var yuansu = $(build2).find('a.zoom[onclick*="Travian.Game.unitZoom(' + a1 + t + ')"]');
            //找兵种等级
            var level_now2 = yuansu.parent().parent().find('.information .title .level').html();
            //console.log(vid+':' + a1 + t + ':' + level_now);
            level_now2 = level_now2.split(' ');
            level_now2 = level_now2[level_now2.length - 1];
				  //找到新的等级 END
                    if ($(build2).find('.under_progress').length > 0 || level_now2*1 > level_now*1) {
                      nono = 'nono';
                    }
                  }
                });
              } else {
                nono = 'nono';
                timeba = 1;
              }
            }
          } else {
            nono = 'nono2';
            console.log(vid + '： 兵种未研发：' + title);
          }
          $.get("{:url('set_task5')}/vid/" + vid + '/id/' + id + '/inctime/' + timeba + '/nono/' + nono,
          function(data) {
            if (data == 'ok') {
              //更新任务成功
              if (nono != 'nono') {
                $("[data-tieid='" + id + "']").remove();
              }
            } else {
              //alert('更新失败');
            }
          });

        }
      });

    }

    //运输
    function startBot6() {
      $.ajax({
        url: "{:url('get_task6')}/uid/{$uid}",
        type: 'get',
        cache: false,
        async: false,
        //
        data: '',
        dataType: 'json',
        success: function(data) {
          $.each(data,
          function(i, son) {
            //历编每个任务
            var arr = [];
            arr[0] = son.id;
            arr[1] = son.x;
            arr[2] = son.y;
            arr[3] = son.mu;
            arr[4] = son.tu;
            arr[5] = son.tie;
            arr[6] = son.liang;
            arr[7] = son.times;
            arr[8] = son.target_vid;
            arr[9] = son.vid;
            var str = arr.toString();
            setTimeout('zao_6("' + str + '")', 500);
          });
        }
      });
      sleep_b();
    }

    function zao_6(str) {
      var arr1 = str.split(",");
      var id = arr1[0];
      var x = arr1[1];
      var t = arr1[2];
      var mu = arr1[3];
      var tu = arr1[4];
      var tie = arr1[5];
      var liang = arr1[6];
      var times = arr1[7];
      var tvid = arr1[8];
      var vid = arr1[9];
      //var timeba, nono;
      $.ajax({
        url: server + "build.php" + "?{$newdid}=" + vid + "&gid=17",
        type: 'get',
        cache: false,
        async: false,
        //
        data: '',
        dataType: 'html',
        success: function(build) {
		//登录检测
			  if ($(build).find(".loginTable").length > 0 || $(build).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
          //console.log('url：'+url);
          var url = server + 'build.php?' + "{$newdid}=" + vid;
          var obj = {};
          obj['ft'] = 'mk1';
          obj['id'] = $(build).find('input[name="id"]').val();
          obj['send3'] = '1';
          /*obj['x'] = x;
							obj['y'] = y;*/
          obj['r1'] = mu;
          obj['r2'] = tu;
          obj['r3'] = tie;
          obj['r4'] = liang;
          obj['getwref'] = tvid;
          obj['s1'] = 'ok';
          $.ajax({
            url: url,
            type: 'post',
            cache: false,
            async: false,
            //
            data: obj,
            dataType: 'html',
            success: function(build2) {
			  //登录检测
			  if ($(build2).find(".loginTable").length > 0 || $(build2).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
              if ($(build2).find('.traders').length > 0) {

                $.get("{:url('set_transport2')}/id/" + id + '/inctime/' + times,
                function(data) {
                  if (data == '1') {
                    //更新任务成功
                  } else {
                    //alert('更新失败');
                  }
                });

              }
            }
          });
        }
      });

    }

    function login_sleep() {
	  var settimeout = $('[name="settimeout"]').val();
      setTimeout('login()', settimeout);
    }

    function login() {
      var obj = {};
      obj['user'] = $('#user{$uid}').attr('data-user');
      obj['pw'] = $('#user{$uid}').attr('data-pwd');
      obj['ft'] = 'a4';
      obj['s2'] = 'go';
      $.ajax({
        url: server + "login.php?m=" + Math.random(),
        type: 'post',
        cache: false,
        async: false,
        //
        data: obj,
        dataType: 'html',
        success: function(login) {
          if ($(login).find('.playerName').length > 0) {
            startBot();
          } else {
            login_sleep();
          }
        }
      });
    }


    //建筑任务检测
    function startBot() {
      $.get("{:url('get_task')}/uid/{$uid}",
      function(data) {
        //if($(data).length>0){
        $.each(data,
        function(i, son) {
          //alert(i);
          var arr = [];
          arr[0] = son.id;
          arr[1] = son.vid;
          arr[2] = son.build;
          arr[3] = son.level;
          arr[4] = '';
          arr[5] = son.type;
          arr[6] = son.newbid;
          var resource = [];
          var href;
          var build;
          var dorf1;
          var name = [];
          if ($('#userinfo').attr('data-version') == '36' || $('#userinfo').attr('data-version') == '42') {
            name[0] = 'Woodcutter';
            name[1] = 'Clay Pit';
            name[2] = 'Iron Mine';
            name[3] = 'Cropland';
          } else {
            name[0] = 'Bosque';
            name[1] = 'Poço de Barro';
            name[2] = 'Mina de Ferro';
            name[3] = 'Campo de Cereal';
          }
          resource[0] = name[0];
          resource[1] = name[1];
          resource[2] = name[2];
          resource[3] = name[3];

          var vid = son.vid;
          $.ajax({
            url: server + "{$dorf}1.php?{$newdid}=" + vid + '&m=' + Math.random(),
            type: 'get',
            cache: false,
            async: false,
            //
            data: '',
            dataType: 'html',
            success: function(dorf1) {
			
			  //登录检测
			  if ($(dorf1).find(".loginTable").length > 0 || $(dorf1).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
			  
			  
              //dorf1 = dorf1a;
              //P田
              //如果是Ptian，就是按库存P田，到等级level级。
              if (son.type == 'ptian') {

                //重写
                var arr_tian = [];
                var i = 0;
                var l1, l2, l3, l4;
                var title, level, buildid, type, arr_temp;
                $(dorf1).find('map area[title!="{$VillageCenter}"]').each(function() {
                  var str = $(this).attr('title');
                  str = str.replace('Woodcutter', "伐木场");
                  str = str.replace('Clay Pit', "黏土矿");
                  str = str.replace('Iron Mine', "铁矿场");
                  str = str.replace('Cropland', "农场");
                  str = str.replace('level', "等级");
                  //tr44
                  str = str.replace('Bosque', "伐木场");
                  str = str.replace('Poço de Barro', "黏土矿");
                  str = str.replace('Mina de Ferro', "铁矿场");
                  str = str.replace('Campo de Cereal', "农场");
                  str = str.replace('nível', "等级");
                  if (str.indexOf(' Custo do melhoramento para nível') >= 0) {
                    var ns1 = 0;　
                    var ns2 = str.indexOf(" Custo do melhoramento para nível");　str = str.substring(ns1, ns2);
                  }
                  str = str.replace("<div style='color:#FFF'><b>", "");
                  str = str.replace("</b>", "");
                  str = str.replace("</div>", "");
                  arr_temp = str.split(' ');
                  //找出名称
                  title = arr_temp[arr_temp.length - 3];
                  //找出等级
                  level = arr_temp[arr_temp.length - 1];
                  //找出bid
                  href = $(this).attr('href');
                  var arr_href = href.split('=');
                  buildid = arr_href[1];
                  //
                  i++;
                  if (level < son.level * 1) {
                    //arr_tian.push($(this));
                    if (str.indexOf("伐木场") >= 0) {
                      l1 = 'you';
                    }
                    if (str.indexOf("黏土矿") >= 0) {
                      l2 = 'you';
                    }
                    if (str.indexOf("铁矿场") >= 0) {
                      l3 = 'you';
                    }
                    if (str.indexOf("农场") >= 0) {
                      l4 = 'you';
                    }
                  }
                });

                //看库存
                var arr_num = [];
                var num;
                $(dorf1).find('{$stock}').each(function() {
                  var text = $(this).text();
                  if (text.indexOf('/') >= 0) {
                    var arr_temp = text.split('/');
                    num = arr_temp[0] * 1;
                  } else {
                    num = $(this).text() * 1;
                  }

                  arr_num.push(num);
                });
				console.log(arr_num);
                //如果没有 you ，也就是次种资源田全部P到指定等级，则此种资源田库存暂设最大数999999999
                if (l1 != 'you') {
                  arr_num[0] = 99999999999;
                }
                if (l2 != 'you') {
                  arr_num[1] = 99999999999;
                }
                if (l3 != 'you') {
                  arr_num[2] = 99999999999;
                }
                if (l4 != 'you') {
                  arr_num[3] = 99999999999;
                }
                //第几个元素的资源库存最少，然后n就是这个上面定义的resource字符串（<div style='color:\\#FFF'><b>Bosque</b>）
                //重写  接下
                //第几个元素的资源库存最少，然后n就是这个上面定义的resource字符串（<div style='color:\\#FFF'><b>Bosque</b>）
                var n = resource[arr_num.indexOf(Math.min.apply(Math, arr_num))];
				//console.log(arr_num);
                var arr_num2 = [];
                var kk = 1;
                //console.log('map area[title*="'+n+'"][title!="{$VillageCenter}"]');
                $(dorf1).find('map area[title*="' + n + '"][title!="{$VillageCenter}"]').each(function() {
                  var str = $(this).attr('title');
				  
                  if (str.indexOf(' Custo do melhoramento para nível') >= 0) {
                    var ns1 = 0;　
                    var ns2 = str.indexOf(" Custo do melhoramento para nível");　str = str.substring(ns1, ns2);
                  }
                  str = str.replace("<div style=color:#FFF><b>", "");
				  str = str.replace("<div style='color:#FFF'><b>", "");
                  str = str.replace("</b>", "");
                  str = str.replace("</div>", "");
                  arr_temp = str.split(' ');
                  //找出等级
                  level = arr_temp[arr_temp.length - 1] * 1;
                  arr_num2.push(level);
                });
                //找到最小等级资源田ID
                var n2 = arr_num2.indexOf(Math.min.apply(Math, arr_num2));
                href = $(dorf1).find('map area[title*="' + n + '"]').eq(n2).attr('href');
				//console.log('arr_num2'+arr_num2);return false;
                var arrr = href.split('=');
                build = arrr[1];
                //
                if (Math.min.apply(Math, arr_num2) < son.level * 1) {
                  console.log(vid + ' 库存：' + arr_num + ' 库存最少资源田的最小等级那个-类型：' + n + ' 序号：' + Math.min.apply(Math, arr_num2) + ' 指定上限等级：' + son.level);
                  //如果最小的指定类型田小于等于设定目标等级，
                  //nono是不删任务，只更新下次时间
                  arr[4] = 'nono';
                } else {
                  var vname = $(dorf1).find('#sidebarBoxVillagelist li.active .name').text();
                  console.log('nono2了，村庄：' + son.vid + ' ' + vname + ' 建筑：' + href + ' 目标等级：' + Math.min.apply(Math, arr_num2) + ' 指定上限等级：' + son.level);
                  //否则跳过，并删除任务
                  //nono2 是直接删除任务
                  arr[4] = 'nono2';
                }
                arr[2] = build;
                var str = arr.toString();
                setTimeout('zao("' + str + '")', 500);
              } else {
                var str = arr.toString();
                setTimeout('zao("' + str + '")', 500);
              }
              //P田

            }
          });
        });
        //}else{
        //}

      });
      setTimeout('startBot_chai()', 500);
    }

    //console.log('村子：'+son.vid+' 目标类型：'+n+' 等级分别是：'+kk+':'+arr_num2.toString());
    //历编所有资源田等级   暂时没使用
    //如果使用就把下面的  if(Math.min.apply(Math, arr_num2)<son.level*1){ 其中的arr_num2改为arr_num3
    /*	var arr_num3 = [];
						$(dorf1).find('map area').each(function(){
						    var str = $(this).attr('title');
						    var n11=str.indexOf("</b> nível ")+11;　
						    var n12=str.indexOf("</div>");　
						    var num3 = str.substring(n11,n12)*1;
						    arr_num3.push(num3);
						});
					*/
    //历编所有资源田等级 end
    function sleep_a() {
      setTimeout('startBot2()', 1000);
    }

    function sleep_c() {
      sleep_b();
    }

    function sleep_b() {
      settimeout = $('[name="settimeout"]').val();
      if ($("#switch").prop("checked")) {
        setTimeout('startBot()', settimeout * 1000);
      } else {
        setTimeout('sleep_c()', settimeout * 1000);
      }

    }

    //开始建筑
    function zao(str) {
      var arr = str.split(",");
      var id = arr[0];
      var vid = arr[1];
      var bid = arr[2];
      var level = arr[3];
      var nono = arr[4];
      var type = arr[5];
      var newbid = arr[6];
	  var timeba;
      //nono2是最低库存的田种已超过 设定目标等级，所以删除任务
      if (nono == 'nono2') {
        $.get("{:url('set_task')}/vid/" + vid + '/uid/' + uid + '/id/' + id + '/inctime/1/nono/' + nono,
        function(data) {});
        $("[data-tid='" + id + "']").remove();
      } else {
        //$.get(server +"build.php?id="+bid+"&{$newdid}="+vid+'&m='+Math.random(),function(build){
        //----
        $.ajax({
          url: server + "build.php?id=" + bid + "&{$newdid}=" + vid + '&m=' + Math.random(),
          type: 'get',
          cache: false,
          async: false,
          //
          data: '',
          dataType: 'html',
          success: function(build) {
		    //登录检测
			  if ($(build).find(".loginTable").length > 0 || $(build).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
            //找到建筑等级
            var jianzhu_level = $(build).find('{$build_level}:eq(0)').text();
            var arr_jianzhu_level = jianzhu_level.split(' ');
            jianzhu_level = arr_jianzhu_level[arr_jianzhu_level.length - 1];
            //alert($(build).find('.small').attr('onclick'));
            //如果是最高等级
            if ($(build).find('{$build_max_level}').length > 0 || jianzhu_level * 1 >= level) {
              //window.wxc.xcConfirm(build);
			  if ($(build).find('{$build_max_level}').length > 0){var b = '最高等级';}else{var b = '非最高等级';}
              console.log('当前建筑等级：' + jianzhu_level + ' 指定等级：' + level + ' - '+b);
              nono = 'nono2';
              $.get("{:url('set_task')}/vid/" + vid + '/uid/' + uid + '/id/' + id + '/inctime/2/nono/' + nono,
              function(data) {});
              $("[data-tid='" + id + "']").remove();
            } else {
              //如果是新建
              if ($(build).find('{$build_btn}').length > 0 || type == 'xinjian') {
                var links;
                if (type == 'xinjian') {
                  if ($('#userinfo').attr('data-version') == '36') { //3.6版本
                    var yuansu = $(build).find('#build a[href*="{$dorf}2.php?a=' + newbid + '&id=' + bid + '&c="]');
                    links = yuansu.attr('href');
                    var html = yuansu.parent().parent().prev().find('.res').html();
                    var n11 = html.indexOf(' title="duration">');
                    var n11 = n11 + 18;　
                    var n12 = html.length;
                  } else { //4.4版本
                    if ($('#userinfo').attr('data-version') == '42') {var a = 'a';}else{var a = 'а';}
                    var yuansu = $(build).find('.contractLink button[onclick*="{$dorf}2.php?'+a+'=' + newbid + '&id=' + bid + '&c="]');
					
                    var onclick = yuansu.attr('onclick');
					//console.log('onclick：'+yuansu);
                    var n15 = onclick.indexOf("window.location.href = '") + 24;　
                    var n16 = onclick.indexOf("'; return false;");　links = onclick.substring(n15, n16);
                    var html = yuansu.parent().prev().find('.clocks').html();
                    var n11 = html.indexOf('        ') + 16;　
                    var n12 = html.indexOf("</span>");　
                  }
                  var clocks = html.substring(n11, n12);
                  //console.log(clocks);return false;
                  //alert(clocks);return false;
                  timeba = timeb(clocks) * 1;
                } else {
                  links = $(build).find('{$build_btn}').attr('onclick');
				  //
				  //如果不只一个升级按钮（t4.4奇迹会有两个按钮，第一个是奇迹改名）
				  if (typeof(links) == 'undefined') {
				    links = $(build).find('{$build_btn}:eq(1)').attr('onclick');
				  }
				  //如果不是t4版本
                  if (typeof(links) == 'undefined') { 
                    links = $(build).find('{$build_btn}').attr('href');
                    clocks = $(build).find('#contract').html();
                    /*var n11 = clocks.indexOf(' title="duration">');
                    var n11 = n11 + 18;　
					//var n12 = clocks.indexOf('|<a href');
					if(n12<0){n12 = clocks.indexOf('<br>',50);}//两个3.6服还不一样，郁闷
					*/
                  } else {
                    var arr = links.split("'");
                    links = arr[1];
                    var clocks = $(build).find('.clocks').html();
					 //t44私服版 粮和其他build里的html不同
					
					/*var n11 = clocks.indexOf(' title="duration">');
					if ($('#userinfo').attr('data-version') == '42') {
					  n11 = n11 + 18;
					}else{
					  n11 = n11 + 23;
					}
                    var n12 = n11 + 8;　
					*/
                  }
				  //var text = clocks.substring(n11, n12);
				  //改为正则
				  var reg = /[0-9]?[0-9]:[0-9]?[0-9]:[0-9]?[0-9]/;
				  var text = clocks.match(reg);
				  //console.log('text:'+text);return false;
				  //console.log('n11:'+n11+' n12:'+n12+' l:'+clocks.length);return false;
				  //console.log('text:'+text);return false;
                  timeba = timeb(text[0]);
                  //alert('sssssss');
                }
                
                //alert(links);return false;
                /////////////////改为AJAX
                if ($('#userinfo').attr('data-version') != '44') {
                  var url = server + links;
                } else {
                  var url = server + links + "&{$newdid}=" + vid;
                }
				//console.log('url:'+url);return false;
                $.ajax({
                  url: url,
                  type: 'get',
                  cache: false,
                  async: false,
                  //
                  data: '',
                  dataType: 'html',
                  success: function(build2) {
				    //登录检测
			  if ($(build2).find(".loginTable").length > 0 || $(build2).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
                    //如果开始了
                    if ($(build2).find('#timer1').length > 0) {
                      //如果是最后一级也删掉任务
                      if (type != 'ptian' && jianzhu_level * 1 + 1 >= level) {
                        nono = 'nono2';
                      } else {
                        nono = 'nono';
                      }
                      if (type == 'xinjian') {
                        nono = 'nono2';
                      }
                      //var timess = $(build2).find('.buildDuration span').text();
                      //var timeba = timeb(timess);
                      $.get("{:url('set_task')}/vid/" + vid + '/uid/' + uid + '/id/' + id + '/inctime/' + timeba + '/nono/' + nono,
                      function(data) {
                        if (data == 'ok') {
                          //更新任务成功
                          if (nono != 'nono') {
                            $("[data-tid='" + id + "']").remove();
                          }
                          read_viliage(vid);
                        } else {
                          //alert('更新失败');
                        }
                      });
                    } else {
                      //alert('建造失败');
                    }
                  }
                });
                /////////////////改为AJAX end
              } else {
                //alert('不能建造');
              }
            }
          }
        });
        //-------
      }

      //sleep_a();
    }

    function startBot_chai() {
      $.ajax({
        url: "{:url('get_task_chai')}/uid/{$uid}",
        type: 'get',
        cache: false,
        async: false,
        //
        data: '',
        dataType: 'json',
        success: function(data) {
          $.each(data,
          function(i, son) {
            //历编每个任务
            var arr = [];
            arr[0] = son.id;
            arr[1] = son.vid;
            arr[2] = son.build;
            arr[3] = son.title;
            var str = arr.toString();
            setTimeout('zao_chai("' + str + '")', 500);
          });
        }
      });
      setTimeout('startBot2()', 500);
    }

    //开始拆
    function zao_chai(str) {
      var arr = str.split(",");
      var id = arr[0];
      var vid = arr[1];
      var bid = arr[2];
      $.ajax({
        url: server + "build.php?gid=15&{$newdid}=" + vid,
        type: 'get',
        cache: false,
        async: false,
        //
        data: '',
        dataType: 'html',
        success: function(build_26) {
		//登录检测
			  if ($(build_26).find(".loginTable").length > 0 || $(build_26).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
          var time1;
          var timeba;
          //如果有select框
          if ($(build_26).find('.dropdown').length > 0) {
            //如果存在这个建筑
            //alert('这个id的select数量:'+$(build_26).find('.dropdown option[value="'+bid+'"]').length);
            //alert('.dropdown option[value="'+bid+'"]');
            //alert('这个id的select数量:'+$(build_26).find('.dropdown option[value="'+bid+'"]').length);
            if ($(build_26).find('.dropdown option[value="' + bid + '"]').length > 0) {
              var form = $(build_26).find('form').eq(0);
              var ac = form.attr('action');
              var obj = {};
              var str = $(build_26).find('.dropdown option[value="' + bid + '"]').text();
              var n11 = str.indexOf("(lvl ") + 5;　
              var n12 = str.indexOf(")");　
              var level = str.substring(n11, n12) * 1;
              obj['type'] = bid;
              //开始拆
              //alert(server + ac);
              $.ajax({
                url: server + ac,
                type: 'post',
                cache: false,
                async: false,
                //
                data: obj,
                dataType: 'html',
                success: function(build_26_2) {
				//登录检测
			  if ($(build_26_2).find(".loginTable").length > 0 || $(build_26_2).find("#login_form").length > 0) {
			    //检测到未登录
			     login();
			     return false;
              }
			  //登录检测 END
                  //如果开始拆了
                  if ($(build_26_2).find('#timer1').length > 0) {
                    time1 = $(build_26_2).find('#build span').text();
                    timeba = timeb(time1);
                    var nono = 'nono';
                    if (level <= 1) {
                      nono = 'nono2';
                      timeba = 1;
                      $("[data-chaiid='" + id + "']").remove();
                    }
                    $.get("{:url('set_task_chai')}/vid/" + vid + '/uid/' + uid + '/id/' + id + '/inctime/' + timeba + '/nono/nono',
                    function(data) {
                      //read_viliage();
                    });

                  } else {
                    //任务失败
                  }
                }
              });
            } else {
              //如果不存在此建筑
              $.get("{:url('set_task_chai')}/vid/" + vid + '/uid/' + uid + '/id/' + id + '/inctime/1/nono/nono2',
              function(data) {
                $("[data-chaiid='" + id + "']").remove();
                //read_viliage();
              });
            }
          }
        }
      });

    }

    /*
$('#read_task1').click(function(){
$('#task_grid').html('');
    var account = $("[name='account']").val();
    $.get("{:url('get_viliage')}/account/"+account,function(data){
	    var vtitle = '';
	    var viliage = '';var vcontent = '';var ii=0;kk=0;
		vtitle   += '<ul class="uk-subnav uk-subnav-pill" data-uk-switcher="{connect:\'#subnav-pill-content-1\'}">';
		vcontent += '<ul id="subnav-pill-content-1" class="uk-switcher">';
		$.each(data,function(i,n){
		    var task = '';var vhtml2 = '';ii++;
			if(ii==1){vtitle   += '<li class=""><a href="#">'+n['vid']+'</a></li>';}else{vtitle   += '<li aria-expanded="false" class=""><a href="#">'+n['vid']+'</a></li>';}
			vcontent += '<li>aaaaaaa'+ii;
		    $.get("{:url('get_task')}/vid/"+n['vid'],'',function(data2){
	            $.each(data2,function(i2,n2){
	                //task += n2['build'];
	                //task += '<br>';
					task +='<button class="uk-button uk-button-primary" type="button" onclick=\'addtask('+n['vid']+'|'+n2['build']+')\'>'+n2['title']+'/'+n2['level']+'</button><br>';
	            });*/
    /*
			viliage += '<div class="uk-width-1-6">';
			viliage += n['vid']+' ：'+n['date']+'<br>';
			viliage += task;
			viliage += '</div>';
			$('#task_grid').append(viliage);
			*/
    /*
	        });
			vcontent += task;
			vcontent += '</li>';
		});
		vtitle   += '</ul>';
		vcontent += '</ul>';
		$('#task_grid').html(vtitle);
		$('#task_grid').append(vcontent);
	});
});
*/
    function ajax(url, type) {
      $.ajax({
        url: url,
        type: 'get',
        cache: false,
        //data: obj,
        dataType: type,
        success: function(data) {
          return data;
        }
      });
    }

    function go1() { //检测所有村庄，下一次建筑时间是否到。
      var account = $("[name='account']").val();
      var server = $("[name='account']").find("option:selected").attr('data-server');
      $.get("{:url('get_viliage')}/account/" + account, '',
      function(data) {
        var viliage = '';
        var start_build_time;
        $.each(data,
        function(i, n) {
          start_build_time = n['start_build_time'];
          var task = '';
          $i2 = 0;
          $.get("{:url('get_taskfirst')}/vid/" + n['vid'], '',
          function(data2) {
            if (data2.build) {
              var build = data2.build;
              //console.log(data);  
              if (n['start'] == 'ok') {
                var drof = server + '/build.php?id=' + data2.build;
                /*
						var rs = ajax(drof,'html');
						alert(rs);
						*/
                $.ajax({
                  url: drof,
                  type: 'get',
                  cache: false,
                  dataType: 'html',
                  success: function(rs) {
                    var click_url = $(rs).find('.small').attr('onclick');
                    if (typeof(click_url) != "undefined") {
                      var arr = click_url.split('\'');
                      //可建造
                      var str;
                      str = n['vid'] + '|'; //村庄数据库ID
                      str += arr[1] + '|'; //建筑升级链接
                      str += data2.id; //建筑数据库ID
                      setTimeout('go2("' + str + '")', 3230);
                      return false;
                    } else {
                      //不能建造
                    }
                  }
                });
              }
            }
          });
        });

      });
    }

    function go2(str) {
      /*
console.log(arg);
return;
alert(arg[0]+'-1');alert(arg[1]+'-2');alert(arg[2]+'-3');*/
      var arg = str.split('|');

      var server = $("[name='account']").find("option:selected").attr('data-server');
      var uid = $("[name='account']").val();
      $.get(server + '/' + arg[1],
      function(data) {
        var time = $(data).find('span[id^="time"]').html();
        var s = time_to_s(time);
        $.get("{:url('set_build_time')}/uid/" + uid + "/vid/" + arg[0] + "/time/" + s + "/bid/" + arg[2],
        function(data) {
          var aa;
        });
      });
    }

    function time_to_s(time) {
      var arr = time.split(':');
      var s = arr[0] * 60 * 60 + arr[1] * 60 + arr[2];
      return s
    }

    $('#stop_task').click(function() {
      window.clearInterval(t1);
    });

    $('#test1').click(function() {
      /*
	var arr_num = [];var num;
    $('body').find('.stockBarButton .value').each(function(){
    num = $(this).text()*1;
    arr_num.push(num);
	
	});
	alert(arr_num.indexOf(Math.min.apply(Math, arr_num)));
	*/

      /*
	var resource = [];
	var href;
	resource[0] = "<div style='color:\\#FFF'><b>Bosque</b>";
	resource[1] = "<div style='color:\\#FFF'><b>Poço de Barro</b>";
	resource[2] = "<div style='color:\\#FFF'><b>Mina de Ferro</b>";
	resource[3] = "<div style='color:\\#FFF'><b>Campo de Cereal</b>";
	var arr_num = [];var num;
	$('.stockBarButton .value').each(function(){
	    num = $(this).text()*1;
	    arr_num.push(num);
		//alert(num);
	});
	var n = resource[arr_num.indexOf(Math.min.apply(Math, arr_num))];
	//alert(n);
	//alert($('map area[title*="'+n+'"]').length);
	var arr_num2 = [];
	$('map area[title*="'+n+'"]').each(function(){
		var str = $(this).attr('title');
		var n11=str.indexOf("</b> nível ")+11;　
		var n12=str.indexOf("</div>");　
		var num2 = str.substring(n11,n12)*1;
		arr_num2.push(num2);
	});
	if(Math.min.apply(Math, arr_num2)<15){
		//如果最小的指定类型田大于等于设定目标等级，则跳过，并删除任务
	    var n2 = arr_num2.indexOf(Math.min.apply(Math, arr_num2));
		href = $('map area[title*="'+n+'"]:eq('+n2+')').attr('href');
	}
	*/
    });

    $('#test2').click(function() {
      $('#bing1').show();
    });

    $('#clsBtn').click(function() {
      //$(this).parent().parent().parent().hide();
      $('#bing1').hide();
    });

    $('#bing_btn').click(function() {
      var btn = $(this);
      btn.attr("disabled", true);
      var obj = $("#form1").serialize();
      var vid = $('#tab1 .uk-active a').attr('title');
      $.ajax({
        url: "{:url('add_attack')}/vid/" + vid,
        type: 'post',
        cache: false,
        data: obj,
        dataType: 'json',
        success: function(rs) {
          alert(rs.b);
        }
      });
    });

    $('.set_zaobing').click(function() {
      //var btn = $(this);
      //btn.attr("disabled", true);
      var obj = $(this).parent().serialize();
      var vid = $('#tab1 .uk-active a').attr('title');
      $.ajax({
        url: "{:url('set_zaobing')}/vid/" + vid,
        type: 'post',
        cache: false,
        data: obj,
        dataType: 'json',
        success: function(rs) {
          if (rs == '1') {
            window.wxc.xcConfirm('更新成功');
          }
        }
      });
    });

    $('.set_task4').click(function() {
      //var btn = $(this);
      //btn.attr("disabled", true);
      var obj = $(this).parent().serialize();
      var vid = $('#tab1 .uk-active a').attr('title');
      $.ajax({
        url: "{:url('set_task4b')}/vid/" + vid,
        type: 'post',
        cache: false,
        data: obj,
        dataType: 'json',
        success: function(rs) {
          if (rs == '1') {
            window.wxc.xcConfirm('更新成功');
          }
        }
      });
    });

    //运输
    $('.set_task6').click(function() {
      //var btn = $(this);
      //btn.attr("disabled", true);
      var obj = $(this).parent().serialize();
      var vid = $('#tab1 .uk-active a').attr('title');
      $.ajax({
        url: "{:url('set_transport')}/vid/" + vid,
        type: 'post',
        cache: false,
        data: obj,
        dataType: 'json',
        success: function(rs) {
          if (rs == '1') {
            window.wxc.xcConfirm('更新成功');
          }
        }
      });
    });</script>

</html>